package org.esgl3d;

import org.esgl3d.primitives.Pyramid;
import org.esgl3d.rendering.RenderActivity;
import org.esgl3d.rendering.Renderer;
import org.esgl3d.scene.MeshNode;
import org.esgl3d.scene.Scene;
import org.esgl3d.scene.SceneNode;

import android.app.Activity;
import android.os.Bundle;

public class ExMinimalActivity extends RenderActivity {
	private MeshNode parentNode;
	private MeshNode childNode;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);		
	}
	
	@Override
	public void setupScenegraph() {
		// get our current renderer instance
		Renderer cur = getRenderer();
		 
		// create a new scene
		Scene myScene = new Scene();
		
		// add our first pyramid
		parentNode = new MeshNode();
		parentNode.setGeometry(Pyramid.createColoredPyramid(cur).getMesh());
		
		// create a second pyramid and attach it to the base with
		// a offset to the right (x)
		childNode = new MeshNode();
		childNode.setGeometry(Pyramid.createColoredPyramid(cur).getMesh());
		childNode.translate(10, 0, 0);
		childNode.attachTo(parentNode);
				
		// add the first node to our scene (obviously the child pyramid is
		// attached too)
		myScene.addChild(parentNode);
		
		// set our scene as the one to render
		cur.setScene(myScene);
	}
	
	@Override
	public void updateScenegraph() {
	
		// rotate the parent node
		parentNode.rotate(1, 0, 1, 0);
		
		// rotate the child node
		// since this node is attached to the parent it gets rotated too
		childNode.rotate(1, 0, 0, 1);
	}
}
